#!/bin/sh

DAEMON=cgroupfs2

start() {
	printf 'Mounting %s: ' "${DAEMON}"
	mkdir -p /sys/fs/cgroup
	mount -t cgroup2 none /sys/fs/cgroup
	status=$?
	if [ "$status" -eq 0 ]; then
		echo "OK"
	else
		echo "FAIL"
	fi
	return "$status"
}

stop() {
	printf 'Unmounting %s: ' "${DAEMON}"
	umount /sys/fs/cgroup
	status=$?
	if [ "$status" -eq 0 ]; then
		echo "OK"
	else
		echo "FAIL"
	fi
	return "$status"
}

restart() {
	stop
	start
}

case "$1" in
	start|stop|restart)
		"$1";;
	reload)
		# Restart, since there is no true "reload" feature.
		restart;;
	*)
		echo "Usage: $0 {start|stop|restart|reload}"
		exit 1
esac
